package com.food.restaurantpro.objects;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import com.food.restaurantpro.RestaurantApp;
import com.food.restaurantpro.utils.Prefs;

public class UserInfo {
	private String userId = "";
	private String generateId = "";
	private String customerName = "";
	private String customerEmail = "";
	private String customerAddress = "";
	private String customerAvataURL = "";
	private String customerPhone = "";
	
	public String getUserId() {
		return userId;
	}
	
	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getGenerateId() {
		return generateId;
	}

	public void setGenerateId(String generateId) {
		this.generateId = generateId;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public String getCustomerEmail() {
		return customerEmail;
	}

	public void setCustomerEmail(String customerEmail) {
		this.customerEmail = customerEmail;
	}

	public String getCustomerAddress() {
		return customerAddress;
	}

	public void setCustomerAddress(String customerAddress) {
		this.customerAddress = customerAddress;
	}

	public String getCustomerAvataURL() {
		return customerAvataURL;
	}

	public void setCustomerAvataURL(String customerAvataURL) {
		this.customerAvataURL = customerAvataURL;
	}
	
	public String getCustomerPhone() {
		return customerPhone;
	}
	
	public void setCustomerPhone(String phone) {
		customerPhone = phone;
	}
	
	public String getUpdateInfoParams() {
		String params = "";
		try {
			params += "&user_id=" + getUserId();
			params += "&address=" + URLEncoder.encode(getCustomerAddress(), "UTF-8");
			params += "&phone=" + getCustomerPhone();
			params += "&email=" + URLEncoder.encode(getCustomerEmail(), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return params;
	}
	
	public static UserInfo getCurrentUserInfo() {
		UserInfo userInfo = new UserInfo();
		Prefs prefs = new Prefs(RestaurantApp.getInstance());
		userInfo.setUserId(prefs.getStringValue("", Prefs.KEY_USER_INFO_ID));
		userInfo.setGenerateId(prefs.getStringValue("", Prefs.KEY_USER_INFO_GENERATE_ID));
		userInfo.setCustomerName(prefs.getStringValue("", Prefs.KEY_USER_INFO_NAME));
		userInfo.setCustomerEmail(prefs.getStringValue("", Prefs.KEY_USER_INFO_EMAIL));
		userInfo.setCustomerAddress(prefs.getStringValue("", Prefs.KEY_USER_INFO_ADDRESS));
		userInfo.setCustomerAvataURL(prefs.getStringValue("", Prefs.KEY_USER_INFO_AVATAR_URL));
		userInfo.setCustomerPhone(prefs.getStringValue("", Prefs.KEY_USER_INFO_PHONE));
		return userInfo;
	}
	
	public static void saveCurrentUserInfo(UserInfo userInfo) {
		Prefs prefs = new Prefs(RestaurantApp.getInstance());
		prefs.putStringValue(userInfo.getUserId(), Prefs.KEY_USER_INFO_ID);
		prefs.putStringValue(userInfo.getGenerateId(), Prefs.KEY_USER_INFO_GENERATE_ID);
		prefs.putStringValue(userInfo.getCustomerName(), Prefs.KEY_USER_INFO_NAME);
		prefs.putStringValue(userInfo.getCustomerEmail(), Prefs.KEY_USER_INFO_EMAIL);
		prefs.putStringValue(userInfo.getCustomerAddress(), Prefs.KEY_USER_INFO_ADDRESS);
		prefs.putStringValue(userInfo.getCustomerAvataURL(), Prefs.KEY_USER_INFO_AVATAR_URL);
		prefs.putStringValue(userInfo.getCustomerPhone(), Prefs.KEY_USER_INFO_PHONE);
	}
	
	public static UserInfo removeCurrentUserInfo() {
		Prefs prefs = new Prefs(RestaurantApp.getInstance());
		prefs.removeValue(Prefs.KEY_USER_INFO_ID);
		prefs.removeValue(Prefs.KEY_USER_INFO_GENERATE_ID);
		prefs.removeValue(Prefs.KEY_USER_INFO_NAME);
		prefs.removeValue(Prefs.KEY_USER_INFO_EMAIL);
		prefs.removeValue(Prefs.KEY_USER_INFO_ADDRESS);
		prefs.removeValue(Prefs.KEY_USER_INFO_AVATAR_URL);
		prefs.removeValue(Prefs.KEY_USER_INFO_PHONE);
		return new UserInfo();
	}
}
